﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.BLL;
using rock.UI.common;
using rock.Model;

namespace rock.UI.fee
{
    public partial class FormTuiYajingUpdate : Form
    {
        BllFEE_SHAOYAJING aBllFEE_SHAOYAJING = new BllFEE_SHAOYAJING();
        ModelFEE_TUIYAJING _ModelFEE_TUIYAJING = new ModelFEE_TUIYAJING();
        public FormTuiYajingUpdate()
        {
            InitializeComponent();

            this.AcceptButton = this.button1;
            this.CancelButton = this.button2;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.WindowState = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = global::rock.Properties.Resources.house;
        }

        public Decimal YAJING_MONEY { get; set; }
        public int YAJING_SEQID { get; set; }

        private void FormTuiYajingUpdate_Load(object sender, EventArgs e)
        {
            Decimal[] infos =  aBllFEE_SHAOYAJING.getNeedTuiYajing(YAJING_SEQID);

            this.groupBox1.Text = "可退最大金额为" + (infos[0] - infos[1]);
            this.textBox4Opera.Text = Manager.getInstance().userAccount.USERNAME;
            this.textBox2Money.Text = (infos[0] - infos[1]) + "";
            this.dateTimePicker2Record.Text = DateTime.Now.ToString(StringUtils.YYYYMMDD);
            this.dateTimePicker1MoneyTime.Text = DateTime.Now.ToString(StringUtils.YYYYMMDD);
            
        }
        private Boolean check()
        {
            try
            {//dalRENT_CUSTOM
                StringUtils.checkIsDecimal(this.textBox2Money.Text, "退押金额");

                StringUtils.checkText(this.textBox1Note.Text, 0, 300, "备注信息");

                if (Decimal.Parse(textBox2Money.Text) <= 0)
                {
                    throw new Exception("你还没有输入退押金额.");
                }

                
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "提示");
                return false;
            }
            return true;
        }



        private void button1_Click(object sender, EventArgs e)
        {
            if (!check())
            {
                return;
            }

            _ModelFEE_TUIYAJING.NOTE = this.textBox1Note.Text;
            _ModelFEE_TUIYAJING.RECEDE_FEE = Convert.ToDecimal(this.textBox2Money.Text);
            _ModelFEE_TUIYAJING.OPEAR_TIME = this.dateTimePicker1MoneyTime.Value;
            _ModelFEE_TUIYAJING.RECORD_TIME = this.dateTimePicker2Record.Value;
            _ModelFEE_TUIYAJING.OPERA_MAN = this.textBox4Opera.Text;
            _ModelFEE_TUIYAJING.RENT_DEOSIT_FEE_SEQID = YAJING_SEQID;
            

            aBllFEE_SHAOYAJING.addTuiYajing(_ModelFEE_TUIYAJING);
            //触发代理
            oneRefreshParentData();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //代理
        public delegate void RefreshParentData();
        public RefreshParentData oneRefreshParentData;

    }
}
